﻿package scrn;


import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.lang.reflect.*;
import javax.swing.*;
import javax.swing.text.*;
import media.*;
import mess.*;
import core.*;


// =============================================================== Основное окно
public class MainFrame extends JFrame {

// ===================================================================
// Константы
private static final long serialVersionUID = 1L;

// Курсор
private static final int SIDE_TOP = Mat.BIT0; // Верхняя часть рамки
private static final int SIDE_BOTTOM = Mat.BIT1; // Верхняя часть рамки
private static final int SIDE_LEFT = Mat.BIT2; // Верхняя часть рамки
private static final int SIDE_RIGHT = Mat.BIT3; // Верхняя часть рамки
private static final int SIDE_OTHER = 0; // Любая другая часть окна

private static final int BORDER_SIZE = 5; // Ширина рамки изменения размера
// окна, в точках

// ==================================================================
// Переменные
private Document doc; // Документ, содержащий текст для отправки
// ContList contList; // Класс обработки списка контактов
private int moveStartX; // Точка начала перемещения окна
private int moveStartY; // Точка начала перемещения окна
private int curDragMode = SIDE_OTHER; // Текущая позиция мыши

private int winX;
private int winY;
private int winW;
private int winH;


public void rePaint() {

	panDrw.repaint();
}


// ===============================================================
// Инициализация
public MainFrame() {

	BufferedImage img = Pic.loadImage("icon.png");

	if (img != null) {
		this.setIconImage(img);
	}

	initComponents();
	jSplitPane3.setDividerLocation(1.0);
	doc = outText.getDocument();
	((ContList) contList).setMyModel();

	butClose.setIcon(Pic.loadIcon("closeInactive.png"));
	butClose.setPressedIcon(Pic.loadIcon("closePressed.png"));
	butClose.setRolloverIcon(Pic.loadIcon("closeActive.png"));

	butMin.setIcon(Pic.loadIcon("minInactive.png"));
	butMin.setPressedIcon(Pic.loadIcon("minPressed.png"));
	butMin.setRolloverIcon(Pic.loadIcon("minActive.png"));

	butPin.setIcon(Pic.loadIcon("btnPinOffInactive.png"));
	butPin.setPressedIcon(Pic.loadIcon("btnPinOffPressed.png"));
	butPin.setRolloverIcon(Pic.loadIcon("btnPinOffActive.png"));

	textLogo.setIcon(Pic.loadIcon("logo.png"));

	// panMain.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));

	img = null;

}


//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

	popContList = new javax.swing.JPopupMenu();
	menuDelCont = new javax.swing.JMenuItem();
	panMain = new javax.swing.JPanel();
	jSplitPane1 = new javax.swing.JSplitPane();
	jSplitPane2 = new javax.swing.JSplitPane();
	panDrw = new DrawPanel();
	jPanel2 = new javax.swing.JPanel();
	jScrollPane1 = new javax.swing.JScrollPane();
	outText = new javax.swing.JTextArea();
	jLabel1 = new javax.swing.JLabel();
	jSplitPane3 = new javax.swing.JSplitPane();
	jPanel3 = new javax.swing.JPanel();
	jScrollPane2 = new javax.swing.JScrollPane();
	contList = new ContList();
	jComboBox1 = new javax.swing.JComboBox();
	jPanel1 = new javax.swing.JPanel();
	jLabel2 = new javax.swing.JLabel();
	butClose = new javax.swing.JButton();
	textLogo = new javax.swing.JLabel();
	butMin = new javax.swing.JButton();
	butPin = new javax.swing.JButton();

	menuDelCont
			.setText("\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u043a\u043e\u043d\u0442\u0430\u043a\u0442");
	menuDelCont.addActionListener(new java.awt.event.ActionListener() {

		public void actionPerformed(java.awt.event.ActionEvent evt) {

			menuDelContActionPerformed(evt);
		}
	});
	popContList.add(menuDelCont);

	setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
	setTitle("\u041c\u043e\u043b\u0427\u0410\u0422.\u041f\u041a");
	setMinimumSize(new java.awt.Dimension(240, 240));
	setName("mainFrame");
	setUndecorated(true);
	addMouseWheelListener(new java.awt.event.MouseWheelListener() {

		public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {

			MainFrame.this.mouseWheelMoved(evt);
		}
	});
	addWindowListener(new java.awt.event.WindowAdapter() {

		public void windowClosing(java.awt.event.WindowEvent evt) {

			formWindowClosing(evt);
		}
	});
	addComponentListener(new java.awt.event.ComponentAdapter() {

		public void componentResized(java.awt.event.ComponentEvent evt) {

			formComponentResized(evt);
		}
	});

	panMain.setBorder(javax.swing.BorderFactory.createBevelBorder(
			javax.swing.border.BevelBorder.RAISED, new java.awt.Color(0, 0, 0),
			java.awt.Color.white, java.awt.Color.black, null));
	panMain.setMaximumSize(new java.awt.Dimension(2048, 2048));
	panMain.setPreferredSize(new java.awt.Dimension(640, 640));
	panMain.addMouseListener(new java.awt.event.MouseAdapter() {

		public void mouseExited(java.awt.event.MouseEvent evt) {

			panMainMouseExited(evt);
		}


		public void mousePressed(java.awt.event.MouseEvent evt) {

			panMainMousePressed(evt);
		}
	});
	panMain.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {

		public void mouseDragged(java.awt.event.MouseEvent evt) {

			panMainMouseDragged(evt);
		}


		public void mouseMoved(java.awt.event.MouseEvent evt) {

			panMainMouseMoved(evt);
		}
	});

	jSplitPane1.setBorder(null);
	jSplitPane1.setDividerLocation(370);
	jSplitPane1.setDividerSize(4);
	jSplitPane1.setResizeWeight(1.0);
	jSplitPane1.setContinuousLayout(true);
	jSplitPane1.setMaximumSize(new java.awt.Dimension(2048, 2048));
	jSplitPane1.setMinimumSize(new java.awt.Dimension(0, 0));
	jSplitPane1.setPreferredSize(new java.awt.Dimension(600, 440));

	jSplitPane2.setBorder(null);
	jSplitPane2.setDividerLocation(400);
	jSplitPane2.setDividerSize(2);
	jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
	jSplitPane2.setResizeWeight(1.0);
	jSplitPane2.setContinuousLayout(true);
	jSplitPane2.setMaximumSize(new java.awt.Dimension(2048, 2048));
	jSplitPane2.setMinimumSize(new java.awt.Dimension(64, 64));

	panDrw.setFocusable(false);
	panDrw.setInheritsPopupMenu(true);
	panDrw.setMinimumSize(new java.awt.Dimension(64, 64));
	panDrw.setPreferredSize(new java.awt.Dimension(300, 200));
	panDrw.addMouseWheelListener(new java.awt.event.MouseWheelListener() {

		public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {

			MainFrame.this.mouseWheelMoved(evt);
		}
	});
	panDrw.addMouseListener(new java.awt.event.MouseAdapter() {

		public void mouseClicked(java.awt.event.MouseEvent evt) {

			MainFrame.this.mouseClicked(evt);
		}
	});
	panDrw.addKeyListener(new java.awt.event.KeyAdapter() {

		public void keyPressed(java.awt.event.KeyEvent evt) {

			MainFrame.this.keyPressed(evt);
		}


		public void keyReleased(java.awt.event.KeyEvent evt) {

			MainFrame.this.keyReleased(evt);
		}
	});

	javax.swing.GroupLayout panDrwLayout = new javax.swing.GroupLayout(panDrw);
	panDrw.setLayout(panDrwLayout);
	panDrwLayout.setHorizontalGroup(panDrwLayout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING)
			.addGap(0, 370, Short.MAX_VALUE));
	panDrwLayout.setVerticalGroup(panDrwLayout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING)
			.addGap(0, 400, Short.MAX_VALUE));

	jSplitPane2.setTopComponent(panDrw);

	jPanel2.setMaximumSize(new java.awt.Dimension(2048, 2048));
	jPanel2.setMinimumSize(new java.awt.Dimension(43, 43));
	jPanel2.setPreferredSize(new java.awt.Dimension(320, 64));

	outText.setColumns(20);
	outText.setFont(new java.awt.Font("SansSerif", 0, 12));
	outText.setLineWrap(true);
	outText.setRows(1);
	outText.setTabSize(4);
	outText.setWrapStyleWord(true);
	outText.setMaximumSize(new java.awt.Dimension(2048, 2048));
	outText.setMinimumSize(new java.awt.Dimension(20, 14));
	outText.setSelectionColor(new java.awt.Color(0, 0, 204));
	outText.addMouseWheelListener(new java.awt.event.MouseWheelListener() {

		public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {

			MainFrame.this.mouseWheelMoved(evt);
		}
	});
	outText.addKeyListener(new java.awt.event.KeyAdapter() {

		public void keyPressed(java.awt.event.KeyEvent evt) {

			outTextKeyPressed(evt);
		}


		public void keyReleased(java.awt.event.KeyEvent evt) {

			outTextKeyReleased(evt);
		}
	});
	jScrollPane1.setViewportView(outText);

	jLabel1.setForeground(java.awt.Color.gray);
	jLabel1.setText("\u0420\u0435\u043a\u043b\u0430\u043c\u0430:");

	javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
	jPanel2.setLayout(jPanel2Layout);
	jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(
					jPanel2Layout.createParallelGroup(
							javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel1,
							javax.swing.GroupLayout.Alignment.TRAILING,
							javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
							.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
									360, Short.MAX_VALUE))));
	jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			javax.swing.GroupLayout.Alignment.TRAILING,
			jPanel2Layout.createSequentialGroup().addComponent(jScrollPane1,
					javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)
					.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(jLabel1)));

	jSplitPane2.setRightComponent(jPanel2);

	jSplitPane1.setLeftComponent(jSplitPane2);

	jSplitPane3.setBorder(null);
	jSplitPane3.setDividerLocation(900);
	jSplitPane3.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
	jSplitPane3.setResizeWeight(1.0);
	jSplitPane3.setContinuousLayout(true);
	jSplitPane3.setOneTouchExpandable(true);

	jPanel3.setMinimumSize(new java.awt.Dimension(80, 64));

	contList.setModel(new DefaultListModel());
	contList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
	contList.setAutoscrolls(false);
	contList.setSelectionBackground(new java.awt.Color(255, 244, 209));
	contList.setSelectionForeground(new java.awt.Color(0, 0, 0));
	contList.addMouseListener(new java.awt.event.MouseAdapter() {

		public void mouseClicked(java.awt.event.MouseEvent evt) {

			contListMouseClicked(evt);
		}
	});
	contList.addKeyListener(new java.awt.event.KeyAdapter() {

		public void keyTyped(java.awt.event.KeyEvent evt) {

			contListKeyTyped(evt);
		}
	});
	jScrollPane2.setViewportView(contList);

	jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
			"Контакты", "Список комнаты" }));
	jComboBox1.setFocusable(false);
	jComboBox1.setRequestFocusEnabled(false);

	javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
	jPanel3.setLayout(jPanel3Layout);
	jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			javax.swing.GroupLayout.Alignment.TRAILING,
			jPanel3Layout.createSequentialGroup().addGroup(
					jPanel3Layout.createParallelGroup(
							javax.swing.GroupLayout.Alignment.TRAILING).addComponent(
							jComboBox1, 0, 182, Short.MAX_VALUE).addComponent(jScrollPane2,
							javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
					.addContainerGap()));
	jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			jPanel3Layout.createSequentialGroup().addComponent(jComboBox1,
					javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
					javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(
					jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 469,
					Short.MAX_VALUE)));

	jSplitPane3.setTopComponent(jPanel3);

	jPanel1.setBackground(new java.awt.Color(255, 255, 255));

	jLabel2.setForeground(new java.awt.Color(204, 204, 204));
	jLabel2
			.setText("\u0417\u0434\u0435\u0441\u044c \u0431\u0443\u0434\u0443\u0442 \u0441\u043c\u0430\u0439\u043b\u044b");

	javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
	jPanel1.setLayout(jPanel1Layout);
	jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			javax.swing.GroupLayout.Alignment.TRAILING,
			jPanel1Layout.createSequentialGroup()
					.addContainerGap(78, Short.MAX_VALUE).addComponent(jLabel2)
					.addContainerGap()));
	jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			javax.swing.GroupLayout.Alignment.TRAILING,
			jPanel1Layout.createSequentialGroup().addContainerGap(
					javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(
					jLabel2).addContainerGap()));

	jSplitPane3.setRightComponent(jPanel1);

	jSplitPane1.setRightComponent(jSplitPane3);

	butClose.setBackground(new java.awt.Color(255, 0, 0));
	butClose.setToolTipText("\u0417\u0430\u043a\u0440\u044b\u0442\u044c");
	butClose.setBorder(javax.swing.BorderFactory
			.createLineBorder(new java.awt.Color(192, 192, 207)));
	butClose.setContentAreaFilled(false);
	butClose.setFocusPainted(false);
	butClose.setFocusable(false);
	butClose.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
	butClose.setIconTextGap(0);
	butClose.setMargin(new java.awt.Insets(0, 0, 0, 0));
	butClose.setMaximumSize(new java.awt.Dimension(38, 18));
	butClose.setMinimumSize(new java.awt.Dimension(38, 18));
	butClose.setPreferredSize(new java.awt.Dimension(38, 18));
	butClose.setRequestFocusEnabled(false);
	butClose.addActionListener(new java.awt.event.ActionListener() {

		public void actionPerformed(java.awt.event.ActionEvent evt) {

			butCloseActionPerformed(evt);
		}
	});

	textLogo.setFont(new java.awt.Font("Tahoma", 1, 12));
	textLogo.setText("jChat");
	textLogo.setMaximumSize(new java.awt.Dimension(110, 42));
	textLogo.setMinimumSize(new java.awt.Dimension(110, 42));
	textLogo.setPreferredSize(new java.awt.Dimension(110, 42));

	butMin.setBackground(new java.awt.Color(255, 0, 0));
	butMin.setToolTipText("\u0421\u0432\u0435\u0440\u043d\u0443\u0442\u044c");
	butMin.setBorder(javax.swing.BorderFactory
			.createLineBorder(new java.awt.Color(192, 192, 207)));
	butMin.setContentAreaFilled(false);
	butMin.setFocusPainted(false);
	butMin.setFocusable(false);
	butMin.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
	butMin.setIconTextGap(0);
	butMin.setMargin(new java.awt.Insets(0, 0, 0, 0));
	butMin.setMaximumSize(new java.awt.Dimension(20, 18));
	butMin.setMinimumSize(new java.awt.Dimension(20, 18));
	butMin.setPreferredSize(new java.awt.Dimension(20, 18));
	butMin.setRequestFocusEnabled(false);
	butMin.addActionListener(new java.awt.event.ActionListener() {

		public void actionPerformed(java.awt.event.ActionEvent evt) {

			butMinActionPerformed(evt);
		}
	});

	butPin.setBackground(new java.awt.Color(0, 255, 0));
	butPin
			.setToolTipText("\u041f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0440\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u043a\u043e\u043d");
	butPin.setBorder(javax.swing.BorderFactory
			.createLineBorder(new java.awt.Color(192, 192, 207)));
	butPin.setContentAreaFilled(false);
	butPin.setFocusPainted(false);
	butPin.setFocusable(false);
	butPin.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
	butPin.setIconTextGap(0);
	butPin.setMargin(new java.awt.Insets(0, 0, 0, 0));
	butPin.setMaximumSize(new java.awt.Dimension(20, 18));
	butPin.setMinimumSize(new java.awt.Dimension(20, 18));
	butPin.setPreferredSize(new java.awt.Dimension(20, 18));
	butPin.setRequestFocusEnabled(false);
	butPin.addActionListener(new java.awt.event.ActionListener() {

		public void actionPerformed(java.awt.event.ActionEvent evt) {

			butPinActionPerformed(evt);
		}
	});

	javax.swing.GroupLayout panMainLayout = new javax.swing.GroupLayout(panMain);
	panMain.setLayout(panMainLayout);
	panMainLayout.setHorizontalGroup(panMainLayout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			javax.swing.GroupLayout.Alignment.TRAILING,
			panMainLayout.createSequentialGroup().addContainerGap().addComponent(
					textLogo, javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(
					javax.swing.LayoutStyle.ComponentPlacement.RELATED, 368,
					Short.MAX_VALUE).addComponent(butMin,
					javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE).addGap(0, 0, 0).addComponent(
					butPin, javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE).addGap(0, 0, 0).addComponent(
					butClose, javax.swing.GroupLayout.PREFERRED_SIZE,
					javax.swing.GroupLayout.DEFAULT_SIZE,
					javax.swing.GroupLayout.PREFERRED_SIZE)).addComponent(jSplitPane1,
			javax.swing.GroupLayout.Alignment.TRAILING,
			javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE));
	panMainLayout.setVerticalGroup(panMainLayout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addGroup(
			panMainLayout.createSequentialGroup().addGroup(
					panMainLayout.createParallelGroup(
							javax.swing.GroupLayout.Alignment.LEADING).addComponent(butClose,
							javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(textLogo,
							javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(butPin,
							javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(butMin,
							javax.swing.GroupLayout.PREFERRED_SIZE,
							javax.swing.GroupLayout.DEFAULT_SIZE,
							javax.swing.GroupLayout.PREFERRED_SIZE)).addComponent(
					jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 502,
					Short.MAX_VALUE)));

	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
	getContentPane().setLayout(layout);
	layout.setHorizontalGroup(layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addComponent(panMain,
			javax.swing.GroupLayout.Alignment.TRAILING,
			javax.swing.GroupLayout.DEFAULT_SIZE, 566, Short.MAX_VALUE));
	layout.setVerticalGroup(layout.createParallelGroup(
			javax.swing.GroupLayout.Alignment.LEADING).addComponent(panMain,
			javax.swing.GroupLayout.Alignment.TRAILING,
			javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE));

	pack();
}// </editor-fold>
//GEN-END:initComponents


private void butPinActionPerformed(java.awt.event.ActionEvent evt) {

	this.setPinState();
}


//========================================== Задать прикрепленное состояние окна
private void setPinState() {

	if (this.isAlwaysOnTop()) {
		this.setAlwaysOnTop(false);
		butPin.setIcon(Pic.loadIcon("btnPinOffInactive.png"));
		butPin.setPressedIcon(Pic.loadIcon("btnPinOnPressed.png"));
		butPin.setRolloverIcon(Pic.loadIcon("btnPinOffActive.png"));

	} else {
		this.setAlwaysOnTop(true);
		butPin.setIcon(Pic.loadIcon("btnPinOnInactive.png"));
		butPin.setPressedIcon(Pic.loadIcon("btnPinOffPressed.png"));
		butPin.setRolloverIcon(Pic.loadIcon("btnPinOnActive.png"));
	}

}


private void panMainMouseExited(java.awt.event.MouseEvent evt) {

	setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}


private void panMainMouseMoved(java.awt.event.MouseEvent evt) {

	switch (getDragMode(evt)) {
		case SIDE_BOTTOM | SIDE_RIGHT:
		case SIDE_TOP | SIDE_LEFT:
			setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
			break;

		case SIDE_BOTTOM | SIDE_LEFT:
		case SIDE_TOP | SIDE_RIGHT:
			setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
			break;

		case SIDE_RIGHT:
		case SIDE_LEFT:
			setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
			break;

		case SIDE_TOP:
		case SIDE_BOTTOM:
			setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
			break;

		default:
			setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}
}


private int getDragMode(MouseEvent evt) {

	int dragMode = SIDE_OTHER;
	int x = evt.getX();
	int y = evt.getY();

	if (x <= BORDER_SIZE) {
		dragMode |= SIDE_LEFT;
	} else if (x > getWidth() - BORDER_SIZE) {
		dragMode |= SIDE_RIGHT;
	}
	if (y <= BORDER_SIZE) {
		dragMode |= SIDE_TOP;
	} else if (y > getHeight() - BORDER_SIZE) {
		dragMode |= SIDE_BOTTOM;
	}

	return dragMode;
}


private void menuDelContActionPerformed(java.awt.event.ActionEvent evt) {

	Mess.m("MainFrame.menuDelContActionPerformed", "Удаляется контакт");
	((ContList) contList).delCont();
}


private void contListMouseClicked(java.awt.event.MouseEvent evt) {

	((ContList) contList).mousePressed(evt, popContList);
	// ((ContList) contList).selCont();
}


private void butMinActionPerformed(java.awt.event.ActionEvent evt) {

	this.setExtendedState(ICONIFIED);
}


private void butCloseActionPerformed(java.awt.event.ActionEvent evt) {

	formWindowClosing(null);
}


private void formWindowClosing(java.awt.event.WindowEvent evt) {

	this.dispose();
	System.exit(NORMAL);
}


private void panMainMousePressed(java.awt.event.MouseEvent evt) {

	moveStartX = evt.getX();
	moveStartY = evt.getY();
	curDragMode = getDragMode(evt);

	Rectangle winR = this.getBounds();

	winX = winR.x;
	winY = winR.y;
	winW = winR.width;
	winH = winR.height;

}


private void panMainMouseDragged(MouseEvent evt) {

	int curX = evt.getXOnScreen();
	int curY = evt.getYOnScreen();

	if (curDragMode == SIDE_OTHER) {
		setLocation(curX - moveStartX, curY - moveStartY);
	} else {

		int newX = winX;
		int newY = winY;
		int newW = winW;
		int newH = winH;

		if ((curDragMode & SIDE_TOP) != 0) {
			newH = winH + (winY - curY);
			newY = curY;
		} else if ((curDragMode & SIDE_BOTTOM) != 0) {
			newH = curY - winY;
		}

		if ((curDragMode & SIDE_LEFT) != 0) {
			newW = winW + (winX - curX);
			newX = curX;
		} else if ((curDragMode & SIDE_RIGHT) != 0) {
			newW = curX - winX;
		}

		setBounds(newX, newY, newW, newH);
	}

}


private void contListKeyTyped(java.awt.event.KeyEvent evt) {

	((ContList) contList).selCont();
}


// ================================================ Изменился размер
// компонентов
private void formComponentResized(java.awt.event.ComponentEvent evt) {

	// Component comp = evt.getComponent();
	// Mess.m("MainFrame.formComponentResized", "Изменен размер компонента "
	// + comp);

	// if (comp == panDrw) { // Изменился размер панели рисования
	// setDrawSize();
	// }
}


// ============================================ Отпущена клавиша в окне
// отправки
private void outTextKeyReleased(java.awt.event.KeyEvent evt) {

	int code = evt.getKeyCode();

	if (code == KeyEvent.VK_ENTER) {
		outText();
	}
}


// ============================================== Нажата клавиша в окне
// отправки
private void outTextKeyPressed(java.awt.event.KeyEvent evt) {

	int len = doc.getLength();
	if (len <= 0) { // Поле текста пустое

		Man.scrMan.keyPressed(evt.getKeyCode());

	}

	int code = evt.getKeyCode();

	if (code == KeyEvent.VK_ENTER) {
		evt.consume();
		outText();
	} else if (code == KeyEvent.VK_TAB) {
		evt.consume();
		contList.requestFocusInWindow();
	}
}


private void mouseClicked(java.awt.event.MouseEvent evt) {

	outText.requestFocusInWindow();
}


private void keyReleased(KeyEvent evt) {

	// Mess.m("keyReleased", "code=" + kevt.getKeyCode());
	Man.scrMan.keyReleased(evt.getKeyCode());
}


private void keyPressed(KeyEvent evt) {

	int code = evt.getKeyCode();

	if (evt.isActionKey()) {
		Man.scrMan.keyPressed(code);
	} else {
		outText.requestFocusInWindow();
	}
}


private void mouseWheelMoved(MouseWheelEvent mevt) {

	int rot = mevt.getWheelRotation();
	// Mess.m("mouseWheelMoved", "rot=" + rot);

	if (rot < 0) {
		Man.scrMan.keyPressed(KeyEvent.VK_UP);
	} else if (rot > 0) {
		Man.scrMan.keyPressed(KeyEvent.VK_DOWN);
	}
}


// ============================================= Извещение о пришедшем
// сообщении
public boolean inText(int contType, int contNum, Message message) {

	this.setTitle(Man.scrMan.getTitStr(contType, contNum, message,
			Setting.MAX_NICK_LEN));

	return false;
}


// ====================================================== Нажата кнопка
// отправки
private void outText() {

	int len = doc.getLength();
	if (len <= Setting.MAX_TEXT_LEN) {
		try {
			Man.scrMan.outText(doc.getText(0, len));
			doc.remove(0, len);
		} catch (BadLocationException e) {
			Mess.err("MainFrame.outText", e);
		}
	} else {
		// TODO вывести сообщение о превышении максимально допустимой длины
	}
}


/**
 * @param args
 *          the command line arguments
 */
public static void main(String args[]) {

	java.awt.EventQueue.invokeLater(new Runnable() {

		public void run() {

			new MainFrame().setVisible(true);
		}
	});

}

//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton butClose;
private javax.swing.JButton butMin;
private javax.swing.JButton butPin;
private javax.swing.JList contList;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JSplitPane jSplitPane2;
private javax.swing.JSplitPane jSplitPane3;
private javax.swing.JMenuItem menuDelCont;
private javax.swing.JTextArea outText;
private javax.swing.JPanel panDrw;
private javax.swing.JPanel panMain;
private javax.swing.JPopupMenu popContList;
private javax.swing.JLabel textLogo;


// End of variables declaration//GEN-END:variables

// ======================================= Выдать текущие размеры поля
// рисования
public void setDrawSize() {

	Insets insets = panDrw.getInsets();
	Dimension dim = panDrw.getSize();
	dim.width -= insets.left + insets.right - 2;
	dim.height -= insets.top + insets.bottom - 2;

	Draw.setDim(dim);
	Mess.m("MainFrame.setDrawSize", "Заданы новые размеры окна отрисовки: "
			+ dim.width + "x" + dim.height);
}


// ===================================================== Обновить выбор
// элемента
public void selUpdate() {

	if (SwingUtilities.isEventDispatchThread()) {
		((ContList) contList).selUpdate();
	} else {
		try {
			java.awt.EventQueue.invokeAndWait(new Runnable() {

				public void run() {

					((ContList) contList).selUpdate();
				}
			});
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
}